package com.gome.ss.core.plugin;

import com.gome.ss.core.schedule.ScheduleCore;
import com.mongodb.DBObject;

public class SpiderLocalPluginActionConfig {
	static final String ACTION_CLICK = "click";
	static final String ACTION_SCROLL = "scroll";
	static final String ACTION_SENDKEY = "sendkey";
	static final String ACTION_TYPE = "type";
	
	String action = "";
	String css = "";
	String tvalue = "";
	long kvalue = 0;
	boolean ismultiple = true;
	boolean overlap = false;
	boolean intoKeyword = false;
	String id = "";
	int sleepTime = 0;   // ms
	int repTimes = 1;
	
	boolean hasDone = false;
	
	public SpiderLocalPluginActionConfig(DBObject obj) {
		this.action = (String) obj.get("action");
		this.css = (String) obj.get("css");
		this.tvalue = (String) obj.get("tvalue");
		
		if (obj.get("kvalue") instanceof java.lang.Integer)
			this.kvalue = (Integer) obj.get("kvalue");
		
		if (obj.get("overlap") != null) {
			this.overlap = (Boolean) obj.get("overlap");
		}
		
		if (obj.get("intoKeyword") != null) {
			this.intoKeyword = (Boolean) obj.get("intoKeyword");
		}
		
		this.ismultiple = (Boolean) obj.get("ismultiple");
		this.id = (String) obj.get("id");
		
		if (obj.get("sleepTime") != null) {
			try {
				this.sleepTime = Integer.valueOf((String)obj.get("sleepTime"));
			} catch (Exception e) {
				this.sleepTime = 0;
			}
		}
		
		if (obj.get("repTimes") != null) {
			try {
				this.repTimes = Integer.valueOf((String)obj.get("repTimes"));
				if (this.repTimes < 1)
					this.repTimes = 1;
			} catch (Exception e) {
				this.repTimes = 1;
			}
		}
	}
	
	public boolean isClick() {
		return this.action.equals(ACTION_CLICK);
	}
	
	public boolean isScroll() {
		return this.action.equals(ACTION_SCROLL);
	}
	
	public boolean isSenkey() {
		return this.action.equals(ACTION_SENDKEY);
	}
	
	public boolean isType() {
		return this.action.equals(ACTION_TYPE);
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public String getCss() {
		return css;
	}

	public void setCss(String css) {
		this.css = css;
	}

	public String getTvalue() {
		return tvalue;
	}

	public void setTvalue(String tvalue) {
		this.tvalue = tvalue;
	}

	public long getKvalue() {
		return kvalue;
	}

	public void setKvalue(long kvalue) {
		this.kvalue = kvalue;
	}

	public boolean isIsmultiple() {
		return ismultiple;
	}

	public void setIsmultiple(boolean ismultiple) {
		this.ismultiple = ismultiple;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getSleepTime() {
		return sleepTime;
	}

	public void setSleepTime(int sleepTime) {
		this.sleepTime = sleepTime;
	}

	public int getRepTimes() {
		return repTimes;
	}

	public void setRepTimes(int repTimes) {
		this.repTimes = repTimes;
	}

	public boolean isHasDone() {
		synchronized(SpiderLocalPluginActionConfig.class) {
			return hasDone;
		}
	}

	public void setHasDone(boolean hasDone) {
		synchronized(SpiderLocalPluginActionConfig.class) {
			this.hasDone = hasDone;
		}
	}

	public boolean isOverlap() {
			return overlap;
	}

	public boolean isIntoKeyword() {
		return intoKeyword;
	}
	
	
}
